package com.cskaoyan.controller.admin;

import com.cskaoyan.bean.BaseRespVo;
import com.cskaoyan.bean.admin.vo.ExpressConfigDataVO;
import com.cskaoyan.bean.admin.vo.MarketConfigDataVO;
import com.cskaoyan.bean.admin.vo.OrderConfigDataVO;
import com.cskaoyan.bean.wx.vo.WxConfigDataVO;
import com.cskaoyan.service.SystemService;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

/**
 * @Author tangjian
 * @Date 2021/10/19 15:28
 * @description
 */

@RestController
@RequestMapping("/admin/config")

public class ConfigController {

    @Autowired
    SystemService systemService;

    @RequiresPermissions("admin:config:mall:list")
    @GetMapping("/mall")
    public BaseRespVo mallConfigGet(){

        MarketConfigDataVO marketConfigDataVO = systemService.queryMallConfig();

        return BaseRespVo.ok(marketConfigDataVO);
    }

    @RequiresPermissions("admin:config:mall:updateConfigs")
    @PostMapping("/mall")
    public BaseRespVo mallUpdatePost(@RequestBody MarketConfigDataVO marketConfigDataVO){
        int update = systemService.update(marketConfigDataVO);
        return BaseRespVo.ok();
    }

    @RequiresPermissions("admin:config:express:list")
    @GetMapping("/express")
    public BaseRespVo expressConfigGet(){

        ExpressConfigDataVO expressConfigDataVO = systemService.queryExpressConfig();

        return BaseRespVo.ok(expressConfigDataVO);
    }

    @RequiresPermissions("admin:config:express:updateConfigs")
    @PostMapping("/express")
    public BaseRespVo expressUpdatePost(@RequestBody ExpressConfigDataVO expressConfigDataVO){

        systemService.update(expressConfigDataVO);

        return BaseRespVo.ok();
    }

    @RequiresPermissions("admin:config:order:list")
    @GetMapping("/order")
    public BaseRespVo orderConfigGet(){

        OrderConfigDataVO orderConfigDataVO = systemService.queryOrderConfig();

        return BaseRespVo.ok(orderConfigDataVO);
    }

    @RequiresPermissions("admin:config:order:updateConfigs")
    @PostMapping("/order")
    public BaseRespVo orderUpdatePost(@RequestBody OrderConfigDataVO orderConfigDataVO){

        int i = systemService.update(orderConfigDataVO);

        return BaseRespVo.ok();
    }

    @RequiresPermissions("admin:config:wx:list")
    @GetMapping("/wx")
    public BaseRespVo wxConfigGet(){

        WxConfigDataVO wxConfigDataVO = systemService.queryWxConfig();

        return BaseRespVo.ok(wxConfigDataVO);
    }

    @RequiresPermissions("admin:config:wx:updateConfigs")
    @PostMapping("/wx")
    public BaseRespVo wxUpdatePost(@RequestBody WxConfigDataVO wxConfigDataVO){

        int i = systemService.update(wxConfigDataVO);

        return BaseRespVo.ok();
    }
}
